# ajax动态加载数据
import requests
class kdj:
    def __init__(self):
        self.url='http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
        self.head={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'}

    def get_url(self):
        city = input("请输入要查询的城市:")
        j = 1
        while 1:
            self.data ={'cname':'' ,
                          'pid': '',
                          'keyword': city,
                          'pageIndex':str(j),
                          'pageSize': '10'}
            response = requests.post(url=self.url,headers=self.head,data=self.data)
            page_text=response.json()
            pageIndex=int(page_text['Table'][0]['rowcount'])
            pageIndex_max = int(pageIndex/10)+1 if pageIndex//10 else pageIndex/10
            for i in page_text['Table1']:
                print({"店名":i['storeName'], "地址":i['addressDetail']})
            print('-'*100)
            if j < pageIndex_max:
                j += 1
            else:
                break

kdj =kdj()
kdj.get_url()